package com.hospitalsystem.controller;

import com.hospitalsystem.entity.PatientRecord;
import com.hospitalsystem.service.PatientRecordService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (PatientRecord)表控制层
 *
 * @author makejava
 * @since 2024-12-28 19:33:12
 */
@RestController
@RequestMapping("patientRecord")
public class PatientRecordController {
    /**
     * 服务对象
     */
    @Resource
    private PatientRecordService patientRecordService;

    /**
     * 分页查询
     *
     * @param patientRecord 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<PatientRecord>> queryByPage(PatientRecord patientRecord, PageRequest pageRequest) {
        return ResponseEntity.ok(this.patientRecordService.queryByPage(patientRecord, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param pRId
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<PatientRecord> queryById(@PathVariable("id")String pRId) {
        return ResponseEntity.ok(this.patientRecordService.queryById(pRId));
    }

    /**
     * 新增数据
     *
     * @param patientRecord 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<PatientRecord> add(PatientRecord patientRecord) {
        return ResponseEntity.ok(this.patientRecordService.insert(patientRecord));
    }

    /**
     * 编辑数据
     *
     * @param patientRecord 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<PatientRecord> edit(PatientRecord patientRecord) {
        return ResponseEntity.ok(this.patientRecordService.update(patientRecord));
    }

    /**
     * 删除数据
     *
     * @param pRId
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(String pRId) {
        return ResponseEntity.ok(this.patientRecordService.deleteById(pRId));
    }

}

